import logging

import pytest

from resource.pom.system_ui import SystemUI


class Test:
    system_ui = SystemUI

    @pytest.mark.parametrize('setup_teardown', [None], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.进入桌面，右上角下划进入控制中心，点击控制中心右上角编辑按钮，长按拖动应用位置')
        device.dropdown_controller_center()
        device.refresh_layout()
        snapshot = device.get_element_by_text('截屏')
        snapshot_x0, snapshot_y0 = device.center_of_element(snapshot)
        locate = device.get_element_by_text('位置信息')
        locate_x0, locate_y0 = device.center_of_element(locate)
        device.click(*self.system_ui.edit_btn)
        device.refresh_layout()
        reset = device.get_element_by_text('重置')
        finish = device.get_element_by_text('完成')
        snapshot = device.get_element_by_text('截屏')
        btn0_x, btn0_y = device.center_of_element(snapshot)
        locate = device.get_element_by_text('位置信息')
        btn1_x, btn1_y = device.center_of_element(locate)
        device.drag(btn0_x, btn0_y - 80, btn1_x, btn1_y - 80)
        device.click_element(finish)
        logging.info('预期结果1.进入快捷开关编辑页面，拖动图标生效，点击完成，返回至控制中心显示无异常/点击重置并确认重置，返回至控制中心显示无异常')
        device.refresh_layout()
        snapshot = device.get_element_by_text('截屏')
        snapshot_x1, snapshot_y1 = device.center_of_element(snapshot)
        locate = device.get_element_by_text('位置信息')
        locate_x1, locate_y1 = device.center_of_element(locate)
        assert (snapshot_x0, snapshot_y0) != (snapshot_x1, snapshot_y1), '图标拖动未生效'
        assert (locate_x0, locate_y0) != (locate_x1, locate_y1), '图标拖动未生效'

        device.click(*self.system_ui.edit_btn)
        device.click_element(reset)
        device.refresh_layout()
        device.click_element(device.get_element_by_text('重置'))
        device.click_element(finish)
        device.refresh_layout()
        snapshot = device.get_element_by_text('截屏')
        snapshot_x2, snapshot_y2 = device.center_of_element(snapshot)
        locate = device.get_element_by_text('位置信息')
        locate_x2, locate_y2 = device.center_of_element(locate)
        assert (snapshot_x0, snapshot_y0) == (snapshot_x2, snapshot_y2), '重置未生效'
        assert (locate_x0, locate_y0) == (locate_x2, locate_y2), '重置未生效'
